package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author wmz
 * @date 2024/1/27 22:56
 * @description ShoppingCartMapper
 */
@Mapper
public interface ShoppingCartMapper {

    /**
     * 根据userid，dishid，setmealid，flavor查询是否存在商品
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 根据id修改number
     * @param cart
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart cart);

    /**
     * 插入商品
     * @param shoppingCart
     */
    void insert(ShoppingCart shoppingCart);

    /**
     * 通过id删除
     * @param cart
     */
    @Delete("delete from shopping_cart where id=#{id}")
    void deleteById(ShoppingCart cart);

    /**
     * 根据userId清空购物车
     */
    @Delete("delete from shopping_cart where user_id=#{userId}")
    void deleteByUserId(Long userId);

    /**
     * 批量插入购物车
     * @param shoppingCartList
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
